#include<iostream>
#include<string.h>
#include<pthread.h>
#include<unistd.h>

pthread_cond_t cond=PTHREAD_COND_INITIALIZER;
pthread_mutex_t mutetx=PTHREAD_MUTEX_INITIALIZER;


void *active(void* argv)
{
    std::string name =static_cast<const char*>(argv);
    while(true)
    {
        pthread_mutex_lock(&mutetx);
        pthread_cond_wait(&cond,&mutetx);
        std::cout<<name<<"活动......."<<std::endl;
        pthread_mutex_unlock(&mutetx);
    }
}


int main()
{
    pthread_t t1,t2;

    pthread_create(&t1,NULL,active,(void *)"thread 1");
    pthread_create(&t2,NULL,active,(void *)"thread 2");


    sleep(3);

    while(true)
    {
        pthread_cond_signal(&cond);
        //pthread_cond_broadcast(&cond);//唤醒所有线程
        sleep(1);
    }

    pthread_join(t1,NULL);
    pthread_join(t2,NULL);

    return 0;
}